package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseSaleAttr;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.BaseSaleAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lfy
 * @Description
 * @create 2022-11-01 10:15
 */
@RequestMapping("/admin/product")
@RestController
public class SaleAttrController {


    @Autowired
    BaseSaleAttrService baseSaleAttrService;

    /**
     * 查询spu的销售属性名和值 的列表；
     * 方便在sku录入的时候，选择这个sku到底是那种销售属性组合
     * @return
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable("spuId")Long spuId){

       List<SpuSaleAttr> spuSaleAttrs =
               baseSaleAttrService.getSpuSaleAttrAndValueList(spuId);

        return Result.ok(spuSaleAttrs);
    }

    /**
     * 查询所有销售属性的名
     * @return
     */
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> list = baseSaleAttrService.list();
        return Result.ok(list);
    }
}
